<?php

// $Id$
//  ------------------------------------------------------------------------ //
//                XOOPS - PHP Content Management System                      //
//                    Copyright (c) 2000 XOOPS.org                           //
//                       <http://www.xoops.org/>                             //
//  ------------------------------------------------------------------------ //
//  This program is free software; you can redistribute it and/or modify     //
//  it under the terms of the GNU General Public License as published by     //
//  the Free Software Foundation; either version 2 of the License, or        //
//  (at your option) any later version.                                      //
//                                                                           //
//  You may not change or alter any portion of this comment or credits       //
//  of supporting developers from this source code or any supporting         //
//  source code which is considered copyrighted (c) material of the          //
//  original comment or credit authors.                                      //
//                                                                           //
//  This program is distributed in the hope that it will be useful,          //
//  but WITHOUT ANY WARRANTY; without even the implied warranty of           //
//  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the            //
//  GNU General Public License for more details.                             //
//                                                                           //
//  You should have received a copy of the GNU General Public License        //
//  along with this program; if not, write to the Free Software              //
//  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA //
//  ------------------------------------------------------------------------ //
/**
 * Function used to display an horizontal menu inside the admin panel
 *
 * Enable webmasters to navigate thru the module's features.
 * Each time you select an option in the admin panel of the news module, this option is highlighted in this menu
 *
 * @package News
 * @author - stolen to the Newbb team ;-)
 * @copyright	(c) The Xoops Project - www.xoops.org
*/

include '../xoops_version.php';

function adminmenu($currentoption = 0, $breadcrumb = '')
{
global $modversion, $adminmenu, $xoopsDB, $xoopsConfig, $xoopsModule;
$myts =& MyTextSanitizer::getInstance();
	
	/* Nice buttons styles */
	echo "
    	<style type='text/css'>
    	#buttontop { float:left; width:100%; background: #e7e7e7; font-size:93%; line-height:normal; border-top: 1px solid black; border-left: 0px solid black; border-right: 0px solid black; margin: 0; }
    	#buttonbar { float:left; width:100%; background: #e7e7e7 url('" . XOOPS_URL . "/modules/".$modversion['dirname']."/images/bg.png') repeat-x left bottom; font-size:93%; line-height:normal; border-left: 0px solid black; border-right: 0px solid black; margin-bottom: 0px; }
    	#buttonbar ul { margin:0; margin-top: 15px; padding:10px 10px 0; list-style:none; }
		#buttonbar li { display:inline; margin:0; padding:0; }
		#buttonbar a { float:left; background:url('" . XOOPS_URL . "/modules/".$modversion['dirname']."/images/left_both.png') no-repeat left top; margin:0; padding:0 0 0 9px; border-bottom:1px solid #000; text-decoration:none; }
		#buttonbar a span { float:left; display:block; background:url('" . XOOPS_URL . "/modules/".$modversion['dirname']."/images/right_both.png') no-repeat right top; padding:5px 15px 4px 6px; font-weight:bold; color:#765; }
		/* Commented Backslash Hack hides rule from IE5-Mac \*/
		#buttonbar a span {float:none;}
		/* End IE5-Mac hack */
		#buttonbar a:hover span { color:#333; }
		#buttonbar #current a { background-position:0 -150px; border-width:0; }
		#buttonbar #current a span { background-position:100% -150px; padding-bottom:5px; color:#333; }
		#buttonbar a:hover { background-position:0% -150px; }
		#buttonbar a:hover span { background-position:100% -150px; }
		</style>";

	$tblColors = array();
	$tblColors = array_pad ($tblColors, count($adminmenu), ""); 
	
	if($currentoption>=0) {
		$tblColors[$currentoption] = 'current';
	}
	echo "<div id='buttontop' style='border-right: 1px solid black;border-left: 1px solid black;margin-bottom:8px;padding-bottom:0;'>"; 
	echo "<table style='width: 100%; padding:0;' cellspacing='0'><tr>";
	echo "<td style=\"width: 60%; font-size: 10px; text-align: left; color: #2F5376; padding: 0 6px; line-height: 18px;\">"; if(isset($modversion['config'])){echo"<a class=\"nobutton\" href=\"../../system/admin.php?fct=preferences&amp;op=showmod&amp;mod=".$xoopsModule->getVar('mid')."\">Preferences</a> | ";} echo"<a href=\"../index.php\">Go to module</a>"; if(isset($modversion['hasHelp'])){echo"| <a href=\"".$modversion['helpUrl']."\">Help</a>";} echo "</td>";
	echo "<td style=\"width: 40%; font-size: 10px; text-align: right; color: #2F5376; padding: 0 6px; line-height: 18px;\"><b>" . $xoopsModule->name() . "  </b> " . $breadcrumb . "</td>";
	echo "</tr></table>";
	echo "<div id='buttonbar'>";
	echo "<ul>";
	for($i=0; $i<count($adminmenu); ++$i){ //XOOPS_ROOT_PATH."/modules/".$modversion['dirname']."/admin/
		echo "<li id='" . $tblColors[$i] . "'><a href='".XOOPS_URL."/modules/".$modversion['dirname']."/".$adminmenu[$i]['link']."'><span>" . $adminmenu[$i]['title'] . "</span></a></li>\n";
	}
	echo "</ul></div>";
	echo "</div><div style='margin-bottom:2px;'>&nbsp;</div>";
	
}


function news_collapsableBar($tablename = '', $iconname = '')
{

    ?>
	<script type="text/javascript"><!--
	function goto_URL(object)
	{
		window.location.href = object.options[object.selectedIndex].value;
	}

	function toggle(id)
	{
		if (document.getElementById) { obj = document.getElementById(id); }
		if (document.all) { obj = document.all[id]; }
		if (document.layers) { obj = document.layers[id]; }
		if (obj) {
			if (obj.style.display == "none") {
				obj.style.display = "";
			} else {
				obj.style.display = "none";
			}
		}
		return false;
	}

	var iconClose = new Image();
	iconClose.src = '../images/close12.gif';
	var iconOpen = new Image();
	iconOpen.src = '../images/open12.gif';

	function toggleIcon ( iconName )
	{
		if ( document.images[iconName].src == window.iconOpen.src ) {
			document.images[iconName].src = window.iconClose.src;
		} else if ( document.images[iconName].src == window.iconClose.src ) {
			document.images[iconName].src = window.iconOpen.src;
		}
		return;
	}

	//-->
	</script>
	<?php
	echo "<h4 style=\"color: #2F5376; margin: 6px 0 0 0; \"><a href='#' onClick=\"toggle('" . $tablename . "'); toggleIcon('" . $iconname . "');\">";
}




	function cityCodes(){

		global $xoopsDB;
		$result = $xoopsDB->query( "SELECT * FROM ".$xoopsDB->prefix("weather")." ORDER By name ASC") ;
		$data = array();
		if ( $result ) {
			while ( $myrow = $xoopsDB->fetchArray($result) ) {
				$data[]=$myrow; 
			}
		}
		
		
		
	include XOOPS_ROOT_PATH."/class/xoopsformloader.php"; 
	$form = new XoopsThemeForm('Add New City Codes To Weather Module', 'config', 'admin_formaction.php', 'POST');
	$form->addElement(new XoopsFormText('Name (City, State):', 'name', '35', '50', '', $required = true));
	$form->addElement(new XoopsFormText('City Code From <a href=\'http://weather.yahoo.com\' TARGET=\'_blank\'>http://weather.yahoo.com</a>:', 'code', '35', '50', '', $required = true));
	$form->addElement(new XoopsFormButton('', 'update', 'Enter', 'submit'));
	$form->addElement(new XoopsFormHidden('action', 'add_city'));
	$form->display();	
			
		
		
	news_collapsableBar('sectionmanager', 'toptopicsmanager');
	echo "<img onclick=\"toggle('toptable'); toggleIcon('toptableicon');\" id='toptopicsmanager' name='toptopicsmanager' src='" . XOOPS_URL . "/modules/weather/images/close12.gif' alt='' /></a>&nbsp; City Codes". ' (' . count($data) . ')'."</h4>";
	echo "<div id='sectionmanager'>
	<!--BEGIN COLLAPSABLE DIV-->
		<table width='100%' class='outer' cellspacing='1'><tr><th colspan='4'>Edit City Codes</th></tr>";
		echo "<tr valign='top' align='left' class='head'><td  width='150'>City</td><td >Code</td><td>Default</td><td>Action</td></tr>";
		
		function oddEven($number){
			if($number & 1){
				return "odd";
			}else{
				return "even";
			}
		}
		
		function isDefault($default){
			if($default == 'true'){
			 return "<td style='background-color:#000000; color:#FFFFFF;'>DEFAULT</td>";
			}else{
			 return "<td>&nbsp;</td>";
			}
		}
		
		function makeDefault($default,$ID,$name){
		if($default != 'true'){
			return " - <a href='index.php?op=default&amp;currentID=0&amp;ID=".$ID."&amp;name=".$name."'>Make Default</a>";
		}
		
		}
		
		
			$x=0;
			foreach ($data as $city) {
				echo "<tr valign='top' align='left' class='".oddEven($x)."'><td >".stripslashes($city['name'])."</td><td >".$city['code']."</td>".isDefault($city['default'])."<td><a href='index.php?op=edit&amp;currentID=0&amp;ID=".$city['ID']."'>Edit</a> - <a href='index.php?op=delete&amp;currentID=0&amp;ID=".$city['ID']."&amp;name=".stripslashes($city['name'])."'>Delete</a>".makeDefault($city['default'],$city['ID'],$city['name'])."</td></tr>";
			  ++$x;
			}
		
	echo "</table>
		<!--END COLLAPSABLE DIV-->
	</div><p></P>";
	
	

	}
	
	
	
	function deleteCity(){
	    global $xoopsDB, $xoopsConfig, $xoopsModule;
		$myts =& MyTextSanitizer::getInstance();
		xoops_confirm(array('action'=>'delete_city', 'ID'=>$_GET['ID'],'name'=>$_GET['name']), 'admin_formaction.php', "Are you sure you want to delete this city: ".$myts->htmlSpecialChars(stripslashes($_GET['name']))."?");

	}



	function editCity(){
	global $xoopsDB;
	$result = $xoopsDB->query( "SELECT * FROM ".$xoopsDB->prefix("weather")." WHERE ID = '".$_GET['ID']."'") ;
	$myrow = $xoopsDB->fetchArray($result);
	include XOOPS_ROOT_PATH."/class/xoopsformloader.php";
	$form = new XoopsThemeForm('Add New City Codes To Weather Modules', 'config', 'admin_formaction.php', 'POST');
	$form->addElement(new XoopsFormText('Name (City, State):', 'name', '35', '50', $myrow['name'], $required = true));
	$form->addElement(new XoopsFormText('City Code From <a href=\'http://weather.yahoo.com\' TARGET=\'_blank\'>http://weather.yahoo.com</a>:', 'code', '35', '50', $myrow['code'], $required = true));
	$form->addElement(new XoopsFormButton('', 'update', 'Enter', 'submit'));
	$form->addElement(new XoopsFormHidden('action', 'edit_city'));
	$form->addElement(new XoopsFormHidden('ID', $_GET['ID']));
	$form->display();		
	}



	function makeDefaultCity(){
	    global $xoopsDB, $xoopsConfig, $xoopsModule;
		$myts =& MyTextSanitizer::getInstance();
		xoops_confirm(array('action'=>'make_default', 'ID'=>$_GET['ID'],'name'=>$_GET['name']), 'admin_formaction.php', "Are you sure you want to make ".$_GET['name']." the default city?");

	}

?>
